package cn.lanqiao.demo.controller;

import cn.lanqiao.demo.entity.Student;
import cn.lanqiao.demo.service.StudentService;
import cn.lanqiao.demo.vo.StudentVaccineVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin  //解决跨域问题
@RequestMapping("/student")
public class StudentController {

    @Resource
    private StudentService studentService ;

    @GetMapping("/getBySno")
    public StudentVaccineVo getBySno(String sno){
        StudentVaccineVo student=studentService.getStudentBySno(sno);
        return student ;
    }

    @GetMapping("/getAll")
    public List<StudentVaccineVo> getAll(){
        List<StudentVaccineVo> list=studentService.getAllStudents();
        return list ;
    }

    @GetMapping("/addStudent")
    public int addStudent(Student student){
        int count=studentService.addStudent(student);
        return count ;
    }

    @GetMapping("/deleteStudent")
    public int deleteStudent(String sno){
        int count=studentService.deleteStudent(sno);
        return count ;
    }

    @GetMapping("/updateStudent")
    public int updateStudent(Student student){
        int count=studentService.updateStudent(student);
        return count ;
    }

    //学生分页请求  pageNum：当前页  pageSize：当前页面展示数目
    @GetMapping("/pageTypeList")
    public List<Student> getGoodsTypeList(int pageNum, int pageSize) {
        //调用业务逻辑方法,返回数据
        return studentService.getList(pageNum,pageSize);
    }
}
